package com.shadow.demo.dictionary.dto;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

@Data
@Accessors(chain = true)
public class DicItemDTO implements Serializable {

	private static final long serialVersionUID = 7621717315901619528L;
	
	private String id;

	private String name;

	private String value;

	private Integer sortNo;

	private String parentId;

	private String dicId;

	private List<DicItemDTO> children;

	public DicItemDTO getChildDicItemByName(String name) {
		if (this.getChildren()==null)
			return null;
		for (DicItemDTO dicItemDTO : this.getChildren()) {
			if (dicItemDTO.getName().trim().equalsIgnoreCase(name))
				return dicItemDTO;
			if (dicItemDTO.getChildren()!=null&&dicItemDTO.getChildren().size()>0){
				DicItemDTO childDictionaryItem = dicItemDTO
						.getChildDicItemByName(name);
				if (childDictionaryItem != null) {
					return childDictionaryItem;
				}
			}
		}
		return null;
	}
}
